﻿<form id="frmBXJGWorkOrderWorkOrder" class="frm-container">
    <input type="hidden" name="id" value="0" />
    <table class="frm-box">
        <tr>
            <th>标题</th>
            <td colspan="3">
                <input name="title" class="easyui-textbox" data-options="width:600, required:true, validType:'length[1,500]',prompt:'简短、准确的标题...'" />
            </td>
        </tr>
        <tr>
            <th class="top">内容</th>
            <td colspan="3" style=" padding:7px 0;">
                <input name="description" class="easyui-textbox" data-options="width:600,multiline:true, height:100,  validType:'length[0,5000]',prompt:'工作内容详细描述...'" />
            </td>
        </tr>
        <tr>
            <th>类别</th>
            <td style="width:200px;"><input name="categoryId" /></td>
            <th>紧急程度</th>
            <td style="width:200px;"><input name="urgencyDegree" /></td>
        </tr>
        <tr>
            <th>处理人</th>
            <td><input name="employeeId" /> </td>
            <th></th>
            <td></td>
        </tr>
        <tr>
            <th>预计开始时间</th>
            <td><input class="easyui-datetimebox" name="estimatedExecutionTime"></td>
            <th>预计结束时间</th>
            <td><input class="easyui-datetimebox" name="estimatedCompletionTime"></td>
        </tr>
        <tr>
            <th>执行时间</th>
            <td><input class="easyui-datetimebox" name="executionTime"></td>
            <th>完成时间</th>
            <td><input class="easyui-datetimebox" name="completionTime"></td>
        </tr>
        <tr>
            <th>状态</th>
            <td><input name="status" /></td>
            <th>状态时间</th>
            <td><input class="easyui-textbox" name="statusChangedTime" data-options="readonly:true" /></td>
        </tr>
        <tr>
            <th class="top">状态说明</th>
            <td colspan="3" style=" padding:7px 0;">
                <input name="statusChangedDescription" class="easyui-textbox" data-options="width:600,multiline:true, height:100, validType:'length[0,500]',prompt:'拒绝原因/完成情况/其它说明...'" />
            </td>
        </tr>
    </table>
</form>
<script>

    (function () {
        const m = 'BXJGWorkOrderWorkOrder';
        const $dlg = $('#dlg' + m);
        const $frm = $dlg.find('form');
        const id = $dlg.data('id');
        const $name = $frm.find('[name="title"]');
        const $cls = $frm.find('[name="categoryId"]');
        const $status = $frm.find('[name="status"]');
        const $employeeId = $frm.find('[name="employeeId"]');
        const $urgencyDegree = $frm.find('[name="urgencyDegree"]');
        const clsId = $dlg.data('clsId');




        $cls.combotree({
            required: true,
            url: abp.appPath + 'api/services/bxjgworkorder/WorkOrderCategoryProvider/GettreeForSelect',
            queryParams: { forType: 4 }
        });

        $status.combobox({
            editable: false,
            url: abp.appPath + 'api/services/bxjgworkorder/WorkOrderCommon/GetAllStatus',
            queryParams: { forType: 4 }
        });

        $urgencyDegree.combobox({
            editable: false,
            url: abp.appPath + 'api/services/bxjgworkorder/WorkOrderCommon/GetAllUrgencyDegree',
            queryParams: { forType: 4 }
        });

        $employeeId.combogrid({
            method: 'GET',
            editable: true,
            mode: 'remote',
            idField: 'id',
            textField: 'name',
            panelWidth: 203,//所有列宽+列数*1px+1px
            delay: 500,
            //pagination: true,
            url: abp.appPath + 'api/services/bxjgworkorder/employee/getall',
            queryParams: { forType: 1 },
            prompt: '==' + abp.localization.bxjgWorkOrder('员工') + '==',
            columns: [[
                { field: 'name', title: '姓名', width: 120 },
                { field: 'phone', title: '电话', width: 120 }
            ]]
        });


        $dlg.data('clickSave', function () {
            //验证录入
            if (!$frm.form('validate'))
                return;

            //处理简单的表单数据
            var postData = $frm.serializeJSON();

            let defer;
            if (id) {
                defer = abp.services.bxjgworkorder.workOrder.update(postData).done(function (d) {
                    abp.notify.success(abp.localization.bxjgUtils('修改') + abp.localization.bxjgUtils('成功') + '!');
                    onSaved('onUpdated');
                });
            } else {
                defer = abp.services.bxjgworkorder.workOrder.create(postData).done(function (d) {
                    abp.notify.success(abp.localization.bxjgUtils('新增') + abp.localization.bxjgUtils('修改') + '!');
                    onSaved('onAdded');
                });
            }
            abp.ui.setBusy($dlg, defer);
        });

        function onSaved(funcName) {
            var f = $dlg.data(funcName);
            if (f)
                f();
        }

        setTimeout(function () {
            $name.next('span').find('input').focus();
        }, 0);

        if (id) {
            let initFormTask = abp.services.bxjgworkorder.workOrder.get({ id: id }).done(function (d) {
                $frm.form('load', d);
            });
            abp.ui.setBusy($dlg, initFormTask);
        } else {
            $cls.combotree('setValue', clsId);
        }
    })();
</script>
